package com.yanqu.road.dao.impl.activity.horserun;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.horserun.config.*;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HorseRunConfigImpl extends TempDao {
    private static String getHorseRunEquipConfigSql = "select * from `t_s_activity_horse_equip` where `activityId`=?";
    public Map<Integer,HorseRunEquipConfig> getHorseRunEquipConfigMap(int activityId) {
        Map<Integer,HorseRunEquipConfig> map = new HashMap<Integer,HorseRunEquipConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunEquipConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunEquipConfig horseRunEquipConfig = new HorseRunEquipConfig();
                horseRunEquipConfig.setActivityId(rs.getInt("activityId"));
                horseRunEquipConfig.setId(rs.getInt("id"));
                horseRunEquipConfig.setName(rs.getString("name"));
                horseRunEquipConfig.setLevel(rs.getInt("level"));
                horseRunEquipConfig.setPlace(rs.getInt("place"));
                map.put(horseRunEquipConfig.getId(),horseRunEquipConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunEventConfigSql = "select * from `t_s_activity_horse_event` where `activityId`=?";
    public Map<Integer,HorseRunEventConfig> getHorseRunEventConfigMap(int activityId) {
        Map<Integer,HorseRunEventConfig> map = new HashMap<Integer,HorseRunEventConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunEventConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunEventConfig horseRunEventConfig = new HorseRunEventConfig();
                horseRunEventConfig.setActivityId(rs.getInt("activityId"));
                horseRunEventConfig.setId(rs.getInt("id"));
                horseRunEventConfig.setShow(rs.getInt("show"));
                horseRunEventConfig.setType(rs.getInt("type"));
                horseRunEventConfig.setParam(rs.getString("param"));
                horseRunEventConfig.setAllMax(rs.getInt("allMax"));
                horseRunEventConfig.setWeight(rs.getInt("weight"));
                map.put(horseRunEventConfig.getId(),horseRunEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunLevelConfigSql = "select * from `t_s_activity_horse_level` where `activityId`=?";
    public Map<Integer,HorseRunLevelConfig> getHorseRunLevelConfigMap(int activityId) {
        Map<Integer,HorseRunLevelConfig> map = new HashMap<Integer,HorseRunLevelConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunLevelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunLevelConfig horseRunLevelConfig = new HorseRunLevelConfig();
                horseRunLevelConfig.setActivityId(rs.getInt("activityId"));
                horseRunLevelConfig.setId(rs.getInt("id"));
                horseRunLevelConfig.setNeedExp(rs.getInt("needExp"));
                horseRunLevelConfig.setAttribute(rs.getInt("attribute"));
                horseRunLevelConfig.setGetSkill(rs.getInt("getSkill"));
                map.put(horseRunLevelConfig.getId(),horseRunLevelConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunRaceCourseConfigSql = "select * from `t_s_activity_horse_racecourse` where `activityId`=?";
    public Map<Integer,HorseRunRaceCourseConfig> getHorseRunRaceCourseConfigList(int activityId) {
        Map<Integer,HorseRunRaceCourseConfig> map = new HashMap<Integer,HorseRunRaceCourseConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunRaceCourseConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunRaceCourseConfig horseRunRaceCourseConfig = new HorseRunRaceCourseConfig();
                horseRunRaceCourseConfig.setActivityId(rs.getInt("activityId"));
                horseRunRaceCourseConfig.setId(rs.getInt("id"));
                horseRunRaceCourseConfig.setTotalNum(rs.getInt("totalNum"));
                horseRunRaceCourseConfig.setExp(rs.getInt("exp"));
                map.put(horseRunRaceCourseConfig.getId(),horseRunRaceCourseConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunSkillConfigSql = "select * from `t_s_activity_horse_skill` where `activityId`=?";
    public Map<Integer,HorseRunSkillConfig> getHorseRunSkillConfigList(int activityId) {
        Map<Integer,HorseRunSkillConfig> map = new HashMap<Integer,HorseRunSkillConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunSkillConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunSkillConfig horseRunSkillConfig = new HorseRunSkillConfig();
                horseRunSkillConfig.setActivityId(rs.getInt("activityId"));
                horseRunSkillConfig.setId(rs.getInt("id"));
                horseRunSkillConfig.setQuality(rs.getInt("quality"));
                horseRunSkillConfig.setName(rs.getString("name"));
                horseRunSkillConfig.setAttributeType(rs.getInt("attributeType"));
                horseRunSkillConfig.setType(rs.getInt("type"));
                horseRunSkillConfig.setSkillNum(rs.getInt("skillNum"));
                horseRunSkillConfig.setWeight(rs.getInt("weight"));
                map.put(horseRunSkillConfig.getId(),horseRunSkillConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunTurnTableConfigSql = "select * from `t_s_activity_horse_turntable` where `activityId`=?";
    public Map<Integer,HorseRunTurnTableConfig> getHorseRunTurnTableConfigList(int activityId) {
        Map<Integer,HorseRunTurnTableConfig> map = new HashMap<Integer,HorseRunTurnTableConfig>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunTurnTableConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunTurnTableConfig horseRunTurnTableConfig = new HorseRunTurnTableConfig();
                horseRunTurnTableConfig.setActivityId(rs.getInt("activityId"));
                horseRunTurnTableConfig.setId(rs.getInt("id"));
                horseRunTurnTableConfig.setType(rs.getInt("type"));
                horseRunTurnTableConfig.setNum(rs.getInt("num"));
                horseRunTurnTableConfig.setIsSpecial(rs.getInt("isSpecial"));
                horseRunTurnTableConfig.setWeight(rs.getInt("weight"));
                map.put(horseRunTurnTableConfig.getId(),horseRunTurnTableConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunTextConfigSql = "select * from `t_s_activity_horse_text` where `activityId`=?";
    public Map<Integer,HorseRunTextConfig> getHorseRunTextConfigMap(int activityId) {
        Map<Integer,HorseRunTextConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunTextConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunTextConfig horseRunTextConfig = new HorseRunTextConfig();
                horseRunTextConfig.setActivityId(rs.getInt("activityId"));
                horseRunTextConfig.setId(rs.getInt("id"));
                horseRunTextConfig.setType(rs.getInt("type"));
                horseRunTextConfig.setMeetText(rs.getString("meetText"));
                horseRunTextConfig.setDealText(rs.getString("dealText"));
                map.put(horseRunTextConfig.getId(),horseRunTextConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorseRunBossConfigSql = "select * from `t_s_activity_horse_boss` where `activityId`=?";
    public Map<Integer,HorseRunBossConfig> getHorseRunBossConfigMap(int activityId) {
        Map<Integer,HorseRunBossConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorseRunBossConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorseRunBossConfig horseRunBossConfig = new HorseRunBossConfig();
                horseRunBossConfig.setActivityId(rs.getInt("activityId"));
                horseRunBossConfig.setId(rs.getInt("id"));
                horseRunBossConfig.setEnergy(rs.getInt("energy"));
                horseRunBossConfig.setArtful(rs.getInt("artful"));
                horseRunBossConfig.setResistance(rs.getInt("resistance"));
                horseRunBossConfig.setExp(rs.getInt("exp"));
                horseRunBossConfig.setNormalLevel(StringUtils.stringToIntegerList(rs.getString("normalLevel"),";"));
                horseRunBossConfig.setMidLevel(StringUtils.stringToIntegerList(rs.getString("midLevel"),";"));
                horseRunBossConfig.setHighLevel(StringUtils.stringToIntegerList(rs.getString("highLevel"),";"));
                map.put(horseRunBossConfig.getId(),horseRunBossConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getHorsRunBossNameConfigSql = "select * from `t_s_activity_horse_boss_name` where `activityId`=?";
    public Map<Integer,HorsRunBossNameConfig> getHorsRunBossNameConfigMap(int activityId) {
        Map<Integer,HorsRunBossNameConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHorsRunBossNameConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HorsRunBossNameConfig horsRunBossNameConfig = new HorsRunBossNameConfig();
                horsRunBossNameConfig.setActivityId(rs.getInt("activityId"));
                horsRunBossNameConfig.setId(rs.getInt("id"));
                horsRunBossNameConfig.setName(rs.getString("name"));
                horsRunBossNameConfig.setMeetText(rs.getString("meetText"));
                horsRunBossNameConfig.setDealText(rs.getString("dealText"));
                map.put(horsRunBossNameConfig.getId(),horsRunBossNameConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }



}
